package cn.elead.chaos.security.configuration;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import cn.elead.chaos.security.exception.SecurityExceptionResolverService;
import cn.elead.chaos.security.rest.AuthEndpoint;
import cn.elead.chaos.security.service.ISpringSecurityService;
import cn.elead.chaos.security.service.PermissionService;
import cn.elead.chaos.security.service.impl.SpringSecurityService;

/**
 * 权限配置加载
 * <p>
 * https://www.jianshu.com/p/0b1131be7ace<br>
 * https://github.com/chilexun/springboot-demo
 * 
 * @author luopeng
 */
@Configuration
public class SecurityBeanConfiguration {

	/**
	 * 权限信息端点
	 * 
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean(AuthEndpoint.class)
	public AuthEndpoint authEndpoint(Environment environment) {
		return new AuthEndpoint(environment);
	}

	/**
	 * 模拟用户权限
	 * 
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean(ISpringSecurityService.class)
	public ISpringSecurityService springSecurityService() {
		return new SpringSecurityService();
	}

	/**
	 * 异常处理
	 * 
	 * @return
	 */
	@Bean
	public SecurityExceptionResolverService securityExceptionResolverService() {
		return new SecurityExceptionResolverService();
	}

	/**
	 * 自定义权限实现
	 * 
	 * @return
	 */
	@Bean("ss")
	public PermissionService permissionService() {
		return new PermissionService();
	}

}
